// ConcreteGLObject3D.cpp

# include "ConcreteGLObject3D.h"

namespace Voltron
{

	ConcreteGLObject3D::ConcreteGLObject3D(): GLObject3D()
	{

	}

	ConcreteGLObject3D::ConcreteGLObject3D(int quantityVerts):
				GLObject3D(quantityVerts)
	{
	}

	ConcreteGLObject3D::ConcreteGLObject3D(int quantityVerts, vec4* positionVerts, vec4* colorVerts, GLuint shaderprogram):
	 			GLObject3D(quantityVerts,positionVerts, colorVerts, shaderprogram)
	{
                _model = identity();
	}


	ConcreteGLObject3D::~ConcreteGLObject3D()
	{
	}

	void ConcreteGLObject3D::render()
	{
		makeActiveObject();
                glUniform1i(SelectFlagLoc, 0);
		glDrawArrays(GL_TRIANGLES, 0, _positionVerts.size());
	}

	void ConcreteGLObject3D::renderSelectionColor()
        {
                syncSelectionColor();
                //Draw the scene.  The flag will force shader to not use shading, but instead use a constant color
                glDrawArrays( GL_TRIANGLES, 0, _positionVerts.size());
                glutPostRedisplay();  //MUST REMEMBER TO CALL POST REDISPLAY OR IT WONT RENDER!
        }

	void ConcreteGLObject3D::setDrawMode(GLenum mode)
	{
                glPolygonMode(GL_FRONT_AND_BACK, mode);
	        if(mode == GL_LINE){
                    glPolygonOffset(1.0,2); //Try 1.0 and 2 for factor and units
	        }
	}

        bool ConcreteGLObject3D::isSelected(GLubyte pixel[4])
        {
                if(_selectionColor[0] == ceil(pixel[0]) && _selectionColor[1] == pixel[1]
                        && _selectionColor[2] == pixel[2] && _selectionColor[3] == pixel[3])
                    return true;
                return false;
        }

        mat4 ConcreteGLObject3D::transformModel(mat4 transform)
        {
            _model = _model * transform;
            return _model;
        }
}

